package com.naiterui.ehp.bs.b2c.order.controller.inner;

import com.naiterui.ehp.bp.bo.b2c.order.ReturnOrderBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BaseExceptionCodes;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.support.mvc.RequestHeaderDecode;
import com.naiterui.ehp.bs.b2c.order.service.IReturnOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 退货订单内部接口
 * @Author gongbaoqiang
 * @Date 2019/9/29 2:33 PM
 */
@Slf4j
@Api(tags = SwaggerTag.INNER_API + SwaggerTag.ORDER)
@RestController
@RequestMapping("b2c/inner/cms/return/orders")
public class InnerReturnOrderController {

    @Autowired
    private IReturnOrderService returnOrderService;

    @ApiOperation(value = "保存退换货订单")
    @PostMapping("save")
    public ResponseVO<Void> save(@RequestBody ReturnOrderBO orderBO, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("保存退换货订单：orderBO={}, operator={}", orderBO.toString(), operator);
        returnOrderService.save(orderBO, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

    @ApiOperation(value = "退换货订单审核")
    @ApiImplicitParam(name = "ids", value = "退换货订单ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/audit")
    public ResponseVO<Void> audit(@RequestBody List<Long> ids, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("退换货订单审核：ids={}", ids.toString());
        returnOrderService.audit(ids, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

    /**
     * <pre>
     *     订单反审：退回到待提交状态
     * </pre>
     *
     * @param ids
     * @return
     * @throws BusinessException
     */
    @ApiOperation(value = "退换货订单反审：退回到待提交状态")
    @ApiImplicitParam(name = "ids", value = "退换货订单ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/reset")
    public ResponseVO<Void> reset(@RequestBody List<Long> ids, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("退换货订单反审：ids={}", ids.toString());
        returnOrderService.reset(ids, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

    @ApiOperation(value = "退换货订单提交")
    @ApiImplicitParam(name = "ids", value = "退换货订单ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/submit")
    public ResponseVO<Void> submit(@RequestBody List<Long> ids, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("退换货订单提交：ids={}", ids.toString());
        returnOrderService.submit(ids, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

    @ApiOperation(value = "退换货订单作废")
    @ApiImplicitParam(name = "ids", value = "退换货订单ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/invalid")
    public ResponseVO<Void> invalid(@RequestBody List<Long> ids, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("退换货订单作废：ids={}", ids.toString());
        returnOrderService.invalid(ids, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

    @ApiOperation(value = "退换货订单确认收货")
    @ApiImplicitParam(name = "ids", value = "退换货订单ID集合", paramType = "body", dataType = "array", required = true)
    @PostMapping("/confirm")
    public ResponseVO<Void> confirm(@RequestBody List<Long> ids, @RequestHeaderDecode String operator) throws BusinessException {
        log.info("退换货订单确认收货：ids={}", ids.toString());
        returnOrderService.confirm(ids, operator);
        return PublicService.returnResponseVO(BaseExceptionCodes.SUCCESS);
    }

}
